package gw.com.android.ui.system;

import android.content.Intent;
import android.os.Bundle;

import com.gwtsz.gts2.hx.R;

import gw.com.android.app.AppContances;
import gw.com.android.ui.BaseActivity;
import gw.com.android.utils.PackStatis;
import www.com.library.app.Logger;

/**
 * 系统设置界面
 * @author reeta
 *
 */
public class AppSettingActivity extends BaseActivity{

	public static AppSettingActivity mInstance = null;
	private String mListTag;
	private AppSettingFragment mSettingFragment;
	private String mTitle;
	private boolean reload = false;

	@Override
	protected void setAcitivityParam() {
		if(null != getIntent()){
			mListTag = getIntent().getStringExtra("mTag");
			mTitle = getIntent().getStringExtra("mTitle");
		}
		mInstance = this;
	}

	@Override
	protected int getLayoutView() {
		return R.layout.activity_app_setting;
	}

	@Override
	protected void initLayoutView() {
		mTitleBar.setAppTitle(mTitle);
		//mTitleBar.setLeftResource(mBackTitle);
		/*if(!mListTag.equals(ConfigType.ABOUT_US_TAG)){
			mTitleBar.setDividerView(false);
		}*/
	}

	@Override
	protected void initViewData() {
		mSettingFragment = AppSettingFragment.newInstance(mListTag, mTitle);
		mCurrentTag = mListTag;
		showFragment(mSettingFragment);
	}

	@Override
	protected void onStart() {
		super.onStart();
		if (reload){
			reload = false;
			mSettingFragment.refreshData();
		}
	}

	@Override protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		PackStatis.getToService(PackStatis.EventAction.LOADING.getValue(),PackStatis.EventCategory.SETTING.getValue(),null,null);
	}

	@Override
	public void finish() {
		super.finish();
		mInstance = null;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mInstance = null;
	}

	@Override
	public void startActivityForResult(Intent intent, int requestCode) {
		if (requestCode == AppContances.REQUEST_SYSTEM_PUSH_CODE){
			// 用此方法打开系统通知时，onActivityResult 会直接收到 cancel 的 resuleCode ，所以，换种实现方式
			reload = true;
		}
		super.startActivityForResult(intent, requestCode);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		Logger.e("返回到系统界面 requestCode == " + requestCode);
		if(requestCode == AppContances.REQUEST_SYSTEM_CODE){
			mSettingFragment.refreshData();
		}
	}
}
